# -*- coding: utf-8 -*-
"""
响应格式化工具
@api-version: 1.0.0
"""

from flask import jsonify

def success_response(data=None, message='success', code=200):
    """成功响应格式"""
    response = jsonify({
        'code': code,
        'success': True,
        'message': message,
        'data': data
    })
    response.status_code = code
    return response

def error_response(message='error', code=400, data=None):
    """错误响应格式"""
    response = jsonify({
        'code': code,
        'success': False,
        'message': message,
        'data': data
    })
    response.status_code = code
    return response

def validation_error_response(errors):
    """数据验证错误响应"""
    return error_response(
        message='数据验证失败',
        code=400,
        data={'errors': errors}
    )

def unauthorized_response(message='未授权访问'):
    """未授权响应"""
    return error_response(message=message, code=401)

def forbidden_response(message='权限不足'):
    """权限不足响应"""
    return error_response(message=message, code=403)

def not_found_response(message='资源不存在'):
    """资源不存在响应"""
    return error_response(message=message, code=404)

def internal_error_response(message='服务器内部错误'):
    """服务器错误响应"""
    return error_response(message=message, code=500)